package worldinruin.gui.imp.gameview;

import java.awt.Dimension;

import javax.swing.Action;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;

import worldinruin.GameDataHandler;
import worldinruin.controllers.ControlFactory;
import worldinruin.controllers.ControlFactory.Controllers;
import worldinruin.core.ITile;
import worldinruin.resources.Components;
import worldinruin.resources.IconMap;
import worldinruin.resources.Keys;
import worldinruin.utils.ResizableLabel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class EmptyTileInfoPanel extends javax.swing.JPanel {
	private JLabel tileDescriptionLabel;
	private ITile tile;
	private JLabel headTileLabel;
	private JButton buildViewButton;
	private ResizableLabel tileIconLabel;
	private JLabel tileRecourceAmountLabel;
	private Action listener;


	/**
	 * Creates an empty tile info panel.
	 * @param tile Tile position.
	 */
	public EmptyTileInfoPanel(ITile tile) {
		super();
		this.tile = tile;
		initGUI();
		initListener();
		updateGUI();
	}
	
	/**
	 * Initiates listeners to components.
	 */
	private void initListener() {
		listener = ControlFactory.getControl(Controllers.GAMEBOARD_CONTROLLER);	
		buildViewButton.addActionListener(listener);
		listener.putValue(Components.buildViewButton, buildViewButton);
		listener.putValue(Keys.BUILDINGVIEWKEY.toString(), tile);
	}
	
	private void updateGUI() {
		//buildViewButton.setVisible(GameDataHandler.getInstance().getGame().getActivePlayer())
	}
	

	/**
	 * Initiates GUI components.
	 */
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(300, 300));
			{
				tileRecourceAmountLabel = new JLabel();
				tileRecourceAmountLabel.setText("Tile's resource amount: ");
			}
			{
				tileIconLabel = new ResizableLabel(IconMap.getInstance().getIcon(tile.getTileType()).getImage());
				tileIconLabel.setPreferredSize(new Dimension(200, 100));
			}
			{
				tileDescriptionLabel = new JLabel();
				tileDescriptionLabel.setText("<html><center>" + tile.getDescription());
				tileDescriptionLabel.setVerticalAlignment(SwingConstants.TOP);
			}
			{
				buildViewButton = new JButton();
				buildViewButton.setText("Construct a building");
			}
			{
				headTileLabel = new JLabel();
				headTileLabel.setText("<html><h2><center>" + tile.getName());
				headTileLabel.setVerticalAlignment(SwingConstants.CENTER);
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addComponent(headTileLabel, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(tileDescriptionLabel, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(tileRecourceAmountLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				        .addComponent(buildViewButton, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(tileIconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 32, Short.MAX_VALUE)))
				.addContainerGap(111, 111));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addComponent(tileIconLabel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)
				.addGap(21)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(tileDescriptionLabel, GroupLayout.PREFERRED_SIZE, 224, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(headTileLabel, 0, 109, Short.MAX_VALUE)
				        .addGap(115))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(tileRecourceAmountLabel, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 78, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addGap(42)
				        .addComponent(buildViewButton, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 22, Short.MAX_VALUE)))
				.addContainerGap(38, 38));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
